package content;

import entity.WarehouseLocal;
import entity.WarehouseLocalHome;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import javax.ejb.FinderException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Oleh
 */
public class WarehouseContent {

    public static ArrayList getAllWarehouses() {
        try {
            Context context = new InitialContext();
            WarehouseLocalHome warehouseHome = (WarehouseLocalHome) context.lookup("java:comp/env/Warehouse");
            Collection collection = warehouseHome.findAllWarehouses();
            Iterator iterator = collection.iterator();
            ArrayList array = new ArrayList();
            while (iterator.hasNext()) {
                array.add(((WarehouseLocal) iterator.next()).getWarehouse());
            }
            return array;
        } catch (NamingException ex) {
            ex.printStackTrace();
        } catch (FinderException ex) {
            ex.printStackTrace();
        }
        return null;
    }
}
